<!DOCTYPE html>
<html lang="en">

	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<!-- STYLESHEETS -->
		<!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
		<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
		<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
		<link rel="stylesheet" type="text/css" href="../../css/responsive.css">

		<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
		<!-- file-input -->
		<link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
		<!-- SELECT2 -->
		<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
		<!-- UNIFORM -->
		<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
		<!-- datatable -->
		<link rel="stylesheet" href="../../js/datatables/datatable.css">
		<!-- WIZARD -->
		<link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css" />
		  <link rel="stylesheet" href="../../js/datepicker/datepicker.css">
		<!-- FONTS 
	<link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
-->
		<!-- JQUERY -->
		<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
		<script src="../../js/common.js"></script>
	</head>

	<body>
		<header class="navbar clearfix" id="header">
		</header>

		<!-- PAGE -->
		<section id="page">
			<!-- SIDEBAR -->
			<div id="sidebar" class="sidebar">
				<div class="sidebar-menu nav-collapse">

					<!-- SIDEBAR MENU -->
					<ul>
						
					</ul>
					<!-- /SIDEBAR MENU -->
				</div>

			</div>
			<!-- /SIDEBAR -->
			<div id="main-content">

				<div class="container">
					<div class="row">
						<div id="content" class="col-lg-12">
							<!-- PAGE HEADER-->
							<div class="row">
								<div class="col-sm-12">
									<div class="page-header">
										<!-- STYLER -->

										<!-- /STYLER -->
										<!-- BREADCRUMBS -->
										<ul class="breadcrumb">
											<li>
												<i class="fa fa-home"></i>
												<a href="index.html">首页</a>
											</li>
											<li>
												<a href="#">商品管理</a>
											</li>
											<li>维护商品</li>
										</ul>
										<!-- /BREADCRUMBS -->

									</div>
								</div>
							</div>
							<!-- /PAGE HEADER -->
							<!-- SAMPLE -->
							<form id="form_giveaway">
							
							<div class="row col-md-12">
								<div class="box border primary" style="margin-left: 20px;">
											<div class="box-title">
												<h4><i class="fa fa-bars"></i>SOURCE值赠品</h4>
											</div>
											<div class="box-body big" style="padding:10px;">												
								
								
										<div class="form-group mrg-bt10-right" style="margin-top:10px;">
											<label class="control-label col-md-2"><span class="required">*</span>活动名称：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="activityName" onfocus="this.select()"  placeholder="请输入活动名称" maxlength="50" />
												<input type="hidden" name="id" />
												<input type="hidden" name="oldSourceCode" />
												<span class="error-span"></span>
											</div>
										</div>
										<div class="form-group mrg-bt10-right" style="margin-top:10px;">
											<label class="control-label col-md-2"><span class="required">*</span>SOURCE值：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="sourceCode" onfocus="this.select()"  placeholder="请输入SOURCE值" maxlength="50" />
												<span class="error-span"></span>
											</div>
										</div>
										<div class="form-group mrg-bt10-right">
											<label class="control-label col-md-2"><span class="required">*</span>订单支付金额：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="payPrice" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);"  onfocus="this.select()"  placeholder="请输入订单支付金额" maxlength="10" />

												<span class="error-span"></span>
											</div>
										</div>
										
										<div class="form-group mrg-bt10-right" style="margin-top:10px;">
											<label class="control-label col-md-2"><span class="required">*</span>赠品SKU：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="skuCode" onfocus="this.select()"  placeholder="请输入赠品SKU" maxlength="50" />
												<span class="error-span"></span>
											</div>
										</div>
										<div class="form-group mrg-bt10-right" style="margin-top:10px;">
											<label class="control-label col-md-2"><span class="required">*</span>赠品总数：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="giveCount"  onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);"   onfocus="this.select()"   placeholder="请输入赠品总数" maxlength="50" />
												<span class="error-span"></span>
											</div>
										</div>
										<div class="form-group mrg-bt10-right" style="margin-top:10px;">
											<label class="control-label col-md-2"><span class="required"></span>已赠数量：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="hasGiveCount"  readonly="readonly" maxlength="50" />
												<span class="error-span"></span>
											</div>
										</div>
										<div class="form-group mrg-bt10-right" style="margin-top:10px;">
											<label class="control-label col-md-2"><span class="required">*</span>是否校验库存：</label>
											<div class="col-md-1 inline">
												<input type="checkbox"  checked="checked" name="checkStock"   />
												
												<span class="error-span"></span>
											</div>
										</div>
										<div class="form-group mrg-bt10-right" id="rangDate">
											<label class="control-label col-md-2"><span class="required">*</span>生效日期：</label>
											<div class="col-md-6 inline" style="display:inline-flex">
												<input type="text" class="form-control width-50 bootstrap-datepicker" name="startDate" style="width:110px" />-
												<input type="text" class="form-control width-50 bootstrap-datepicker" name="endDate" style="width:120px"/>
												<span class="error-span"></span>
											</div>
										</div>
										<div class="form-group mrg-bt10-right" style="margin-top:10px;">
											<label class="control-label col-md-2"><span class="required">*</span>每个订单赠送数量：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="giveNumber"  value="1"  disabled= "true" placeholder="请输入每个订单赠送数量" maxlength="50" />
												<span class="error-span"></span>
											</div>
										</div>
									
	
							</div>
									
							  </div>
						    </div>	
							</form>
							<div class="row" style="height: 30px;">
								<div class="col-md-12" style="text-align: center;">
									<div class="box ">
										<a href="#"  class="btn btn-success config bt-submit" style="width: 100px">
											保存
										</a>
									</div>
								</div>
					           </div>	
									</div>
								</div>
										
							
							<!-- /SAMPLE -->

							<div class="footer-tools">
								<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
							</div>
						</div>
						<!-- /CONTENT-->
					</div>
				</div>
			</div>
		</section>
		<!--/PAGE -->
		<!-- JAVASCRIPTS -->
		<!-- Placed at the end of the document so the pages load faster -->

		<!-- BOOTSTRAP -->
		<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>

		<!-- BLOCK UI -->
		<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
		<!--bootbox-->
		<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
		<!-- AUTOSIZE -->
		<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
		<!-- spinner -->
		<script src="../../js/spinner/spin.js"></script>
		<!-- INPUT MASK -->
		
		<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
			<!-- UNIFORM -->
	<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
		<!-- DATA TABLES -->
		<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
		<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>


		<!-- SELECT2 -->
		<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
	
        <script type="text/javascript" src="../../js/datepicker/datepicker.js"></script>
        <script src="../../js/jquery-validate/jquery.validate.min.js"></script>
		<!-- COOKIE -->
		<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
		<!-- CUSTOM SCRIPT -->
		<script src="../../js/script.js"></script>

		<script src="../../js/Sortable.min.js"></script>
		<script>
			var AddGiveaway = function() {
			var gaform = $('#form_giveaway');
			var id,flag;
			var formValiInit=function(){
	            gaform.validate({
	                doNotHideMessage: true,
					errorClass: 'error-span',
	                errorElement: 'span',
	                rules: {                	 
	                	activityName:{
	                		required:true
	                	},                	
						sourceCode: {
	                        required: true                        
	                    },
	                    skuCode: {
	                        required: true                        
	                    }
	                },
	                highlight: function (element) { 
	                    $(element)
	                        .closest('.form-group').removeClass('has-success').addClass('has-error'); 
	                },
	
	                unhighlight: function (element) { 
	                    $(element)
	                        .closest('.form-group').removeClass('has-error'); 
	                },	
	                success: function (label) {
	                    if (label.attr("for") == "gender") { 
	                        label.closest('.form-group').removeClass('has-error').addClass('has-success');
	                        label.remove(); 
	                    } else { 
	                        label.addClass('valid') 
	                        .closest('.form-group').removeClass('has-error').addClass('has-success'); 
	                    }
	                }
				 });
			};
			
			var saveGiveaway=function(){
				if (gaform.valid() == false)return false;			
	            var giveaway={};
	               if(id!=null)
	               giveaway.id=id;
	               giveaway.activityName=$("input[name=activityName]").val();	            
	               giveaway.sourceCode=$("input[name=sourceCode]").val();	               
	               giveaway.oldSourceCode=$("input[name=oldSourceCode]").val();	               
	               giveaway.payPrice=$("input[name=payPrice]").val();	
	               giveaway.skuCode=$("input[name=skuCode]").val();	  
	               giveaway.giveCount=$("input[name=giveCount]").val();	  
	               giveaway.startDate=$("input[name=startDate]").val();
	               giveaway.endDate=$("input[name=endDate]").val();
	               giveaway.giveNumber=$("[name=giveNumber]").val();
	               giveaway.checkStock=$("[name=checkStock]").prop("checked");
	                            
	              
	               $.blockUI();
	               var url= App.getContextPath() + "admin/activity/saveGiveaway.do";
	               if(id!=null)
	                     url=App.getContextPath() + "admin/activity/updateGiveaway.do";
	              
	               $.ajax({
						type: "post",
						url: url,
						data:$.param({giveaway:JSON.stringify(giveaway)}),
						async: true,
						success: function(result) {
						console.log(result);
						$.unblockUI();
						if(result.type=="error"){
							$.alert(result.extra);
							
						}else{
						  location.href="activity_giveaway_list.html";
						}
						}						
					});
			};

	         

	         

	       
	         //获取SOURCE值赠品详情
	         var getGiveaway=function(id){
	           $.ajax({
						type: "post",
						url: App.getContextPath() + "admin/activity/getGiveawayById.do",
						data:{id:id},
						async: true,
						success: function(result) {
						    $("[name=activityName]").val(result.activityName);
						    $("[name=sourceCode]").val(result.sourceCode);
						    $("[name=oldSourceCode]").val(result.sourceCode);
						    $("[name=payPrice]").val(result.payPrice);
						    $("[name=skuCode]").val(result.skuCode);
						    $("[name=giveCount]").val(result.giveCount);
						    $("[name=hasGiveCount]").val(result.hasGiveCount);
						    if(!result.checkStock){
						    	$("[name=checkStock]").removeAttr('checked');
						    }
						    
						    $("[name=startDate]").val(new Date(parseInt(result.startDate)).format("yyyy-MM-dd"));
						    $("[name=endDate]").val(new Date(parseInt(result.endDate)).format("yyyy-MM-dd"));
					    }             					
					});
	         };
	       
			
				return {
					init: function() {
					  App.init();
					   formValiInit();
					   $.initDate($("#rangDate"),0,15);					  
					   $("input[name=startDate]").bsdatepicker("setValue",$.nowDate());
					   $(".bt-submit").click(saveGiveaway);
					    flag=$.getUrlParam("flag");
						id=$.getUrlParam("id");
						if(id!=null){getGiveaway(id);}
						
					}
				}
			}();
			$(function() {
				$("#header").load("../head.html");
				AddGiveaway.init();
			});
		</script>

		<!-- /JAVASCRIPTS -->
	</body>

</html>